import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { TestDetailsButton, ExecuteButton, ExamineFillButton } from '../Common/options'
import { MixPlatHandleType, ProjectList } from '../Common/Conversion'

export const CementMixingStationsExceeded = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const mixPlatHandleType = await MixPlatHandleType()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, ODischargingTime: 'desc@0' },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'CementMixingStationsExceeded' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            { ...commonTableList.StartTime, hideInTable: true },
            { ...commonTableList.EndTime, hideInTable: true },
            {
                dataIndex: 'matName',
                title: '预警分类',
                valueType: 'select',
                valueEnum: BuiltInData.matName,
                align: 'center',
                width: 150,
            },
            {
                dataIndex: 'alarmlve',
                title: '报警等级',
                valueType: 'select',
                valueEnum: BuiltInData.alarmlve,
                align: 'center',
                width: 150,
            },
            {
                dataIndex: 'uporDown',
                title: '报警类型',
                valueType: 'select',
                valueEnum: BuiltInData.uporDown,
                align: 'center',
                width: 150,
            },
            {
                dataIndex: 'dischargingTime',
                title: '出料时间',
                valueType: 'input',
                hideInSearch: true,
                width: 150,
                align: 'center',
            },
            {
                dataIndex: 'equipmentCode',
                title: '设备编号',
                valueType: 'input',
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'projectName',
                title: '工程名称',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'pouringPosition',
                title: '浇筑部位',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'strengthGrade',
                title: '强度等级',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'quantityAct',
                title: '实际方量(m³)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'waterAct',
                title: '水(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'cementAct',
                title: '水泥(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'sandAct',
                title: '砂(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'gravelAct',
                title: '碎石(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'flyashAct',
                title: '粉煤灰(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'slagPowderAct',
                title: '矿粉(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'waterReducerAct',
                title: '减水剂(kg)',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'excessState',
                title: '是否超标',
                hideInSearch: true,
                valueType: 'select',
                valueEnum: BuiltInData.excessState,
                width: 150,
            },
            commonTableList.isEnabled,
            {
                dataIndex: 'mixPlatHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                hideInSearch: true,
                valueEnum: mixPlatHandleType,
                width: 180,
            },
            {
                dataIndex: 'remark',
                title: '意见说明',
                valueType: 'input',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'handleUserName',
                title: '审核人',
                valueType: 'select',
                hideInSearch: true,
                valueEnum: {},
                width: 150,
            },
            {
                dataIndex: 'handleTime',
                title: '审核时间',
                valueType: 'select',
                hideInSearch: true,
                valueEnum: {},
                width: 150,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { cementMixingStationDataUuid, mixPlatHandleTypeUuid, isEnabled, uuid } = record
                    return [
                        <TestDetailsButton
                            key="test"
                            title="查看详情"
                            OptionsEvent={OptionsEvent}
                            data={{
                                type: 'CementMixingStations',
                                title: '水泥拌合站详情',
                                data: { uuid: cementMixingStationDataUuid, url: 'getCementMixingStationsID' },
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === 'a30fc954-4ee3-4659-bd67-51addb6357b8') !== -1 &&
                            !mixPlatHandleTypeUuid && (
                                <ExamineFillButton
                                    key="Examine"
                                    OptionsEvent={OptionsEvent}
                                    title="处理意见"
                                    data={{
                                        options: mixPlatHandleType,
                                        groupId: uuid,
                                        url: 'posAsphaltExceededDatasUpdateRemark',
                                        actionRef,
                                    }}
                                />
                            ),

                        Permission.findIndex(v => v.uuid === 'a30fc954-4ee3-4659-bd67-51addb6357b8') !== -1 &&
                            isEnabled === 0 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="patCementMixingStations"
                                    path={[cementMixingStationDataUuid, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'a30fc954-4ee3-4659-bd67-51addb6357b8') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="two"
                                    title="禁用"
                                    danger={true}
                                    url="patCementMixingStations"
                                    path={[cementMixingStationDataUuid, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                    ]
                },
            },
        ],
    }
    return data
}
